package com.medical.mapi;

import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by junzi on 2016/10/20.
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public JSONResult defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
        if(e instanceof BadSqlGrammarException){
            return new JSONResult("500", "数据库操作失败");
        }
        return new JSONResult("500", "系统内部出错");
    }
}
